package dataTree;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import dataNode.DataNodeDesc;
import dataTable.DataTable;

import java.util.List;
import java.util.Map;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;

public class DataTree extends Composite {
	private Tree tree;
	private DataTable dt;
	private TreeViewer treeViewer ;
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public DataTree(Composite parent, int style,List list,DataTable dt) {
		super(parent, style);
		this.dt=dt;
		setLayout(new FillLayout(SWT.HORIZONTAL));
		
		treeViewer= new TreeViewer(this, SWT.BORDER);
		tree= treeViewer.getTree();

		treeViewer.setContentProvider(new TreeContentProvider());
		treeViewer.setLabelProvider(new TreeLabelProvider());
		treeViewer.setInput(list);
		
		tree.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				Point point=new Point(e.x,e.y);
				TreeItem item=tree.getItem(point);	
				if(item != null) {
				DataTreeNode m=(DataTreeNode)item.getData();
				List<DataNodeDesc> n =m.getDataMapNode();
				dt.refreshTable();
				for(DataNodeDesc dnd:n) {
					dt.addNodeDesc(dnd);
				}
				
			}
			}
		});
		
	}

	public TreeViewer getTreeViewer() {
		return treeViewer;
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
